package com.woniu.controller;

import com.woniu.entity.PageData;
import com.woniu.entity.Result;
import com.woniu.entity.dto.CollectDTO;
import com.woniu.pojo.Collect;
import com.woniu.service.ICollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaosong
 * @since 2023-04-01
 */
@RestController
@RequestMapping("/collect")
@Slf4j
@Api(tags = "收藏管理")
public class CollectController extends BaseController{

    @Autowired
    private ICollectService collectService;

    /*查询收藏表并分页*/
    @PostMapping("/searchPage/{currentPage}/{pageSize}")
    @ApiOperation("分页查询")
    public Result searchPage(@PathVariable Integer currentPage,
                             @PathVariable Integer pageSize,
                             @RequestBody CollectDTO collectDTO){
        PageData pageData = collectService.searchPage(currentPage,pageSize,collectDTO);
        return toDataResult(pageData);
    }

    /*新增收藏*/
    @PostMapping("/insert")
    @ApiOperation("新增收藏")
    public Result increase(@RequestBody Collect collect){

        Boolean flag = collectService.increase(collect);
        return toResult(flag);
    }

    /*单个删除收藏*/
    @PostMapping("/deleteById/{id}")
    @ApiOperation("删除收藏")
    public Result decrease(@PathVariable Integer id){

        Boolean flag = collectService.decrease(id);
        return toResult(flag);

    }

    /*批量删除收藏*/
    @PostMapping("/deletePart")
    @ApiOperation("批量删除收藏")
    public Result deletePart(@RequestBody List<Integer> ids){
        Boolean flag = collectService.deletePart(ids);
        return toResult(flag);
    }
}
